<?php
/**
 * Created by PhpStorm.
 * User: sunquan
 * Date: 2019/3/5
 * Time: 16:02
 */

namespace App\Services\Space;

use App\Services\CommonService;
use App\Model\Quiz;
use App\Model\Space;
use App\Model\Test;
use App\Model\TestSubject;
use Illuminate\Support\Facades\DB;

class SpaceService extends CommonService
{
    /*
     *  查询轮播如图
     */
    static function image(){
        $image=Quiz::all();
        foreach ( $image as &$v ){
            $v = (array)$v;
        }
        return $image;
    }

    /*
     *  航运空间评论
     */
    static function comment(){
        $res=Space::all();
        foreach ( $res as &$v ){
            $v = (array)$v;
        }
        return $res;
    }

    /*
     *  发布动态
     */
    static function addfb($arr){
        $res = array();
        $a = rand(100,999);
        $res['head_img'] = $arr['img'];
        $res['head'] = "游客".$a;
        $res['head_brief'] = $arr['info'];
        $res['image'] = $arr['img'];
        $id=DB::table("space")->insertGetId($res);
        return $id;
    }


    /*
     *  查看航运测试的列表
     */
    static function testlist(){
        $res=Test::all();
        foreach ( $res as &$v ){
            $v = (array)$v;
        }
        return $res;
    }
    /*
     *  查看航运测试的列表
     * $testid  测试题目 id
     */
    static function testlists($testid){
        //根据主键查询 查询一条数据
        $res=TestSubject::where('testid',$testid)->get();
        foreach ( $res as &$v ){
            $v = (array)$v;
        }
        return $res;
    }

    /*
     *  测试题搜索
     *  $sou 搜索的题目名称
     */
    static function testsou($sou){
        $res = DB::select("select * from test where testname like '%$sou%'");
        return $res;
    }
}